//
//  YDOAProChangePresentVC.swift
//  YDOAProduct
//
//  Created by YDWY on 2017/5/31.
//  Copyright © 2017年 Allen. All rights reserved.
//

import UIKit



class YDOAProChangePresentVC: UIViewController {

    @IBOutlet weak var userBtn: UIButton!
    @IBOutlet weak var userLab: UILabel!
    @IBOutlet weak var bumenBtn: UIButton!
    @IBOutlet weak var bumenLab: UILabel!
    @IBOutlet weak var oldNewBtn: UIButton!
    @IBOutlet weak var oldNewLab: UILabel!
    
    
    var btntitle : String?//点击的标题
    
    var type : Int? //修改的类型0:  修改使用人 1:修改新旧程度 2：修改使用部门
    
    var btnclickType : Int? //点击按钮的类型 0：使用人 1：部门 2：新旧程度
    
    
    var userData:[[String : String]]? = Array()
    var bumenData:[[String : String]]? = Array()
    var oldNewData:[[String : String]]? = Array()
    
    
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        setupUI()
        //获取使用人、使用本部门、新旧程度的数据
        getChooseData()
        
        switch type! {
        case 0:
            YMLog.log(item: "修改使用人\(type)")
            userBtn.isHidden = false
            userLab.isHidden = false
            bumenBtn.isHidden = true
            bumenLab.isHidden = true
            oldNewBtn.isHidden = true
            oldNewLab.isHidden = true
            
        case 1:
            YMLog.log(item: "修改新旧程度\(type)")
            userBtn.isHidden = true
            userLab.isHidden = true
            bumenBtn.isHidden = true
            bumenLab.isHidden = true
            oldNewBtn.isHidden = false
            oldNewLab.isHidden = false
        case 2:
            YMLog.log(item: "修改使用部门\(type)")
            userBtn.isHidden = true
            userLab.isHidden = true
            bumenBtn.isHidden = false
            bumenLab.isHidden = false
            oldNewBtn.isHidden = true
            oldNewLab.isHidden = true
        case 3:
            YMLog.log(item: "修改全部\(type)")
        default:
            break

        }
        
        // Do any additional setup after loading the view.
    }

    //设置按钮界面的边框
    fileprivate func setupUI(){
        userBtn.layer.borderColor = UIColor.lightGray.cgColor
        userBtn.layer.borderWidth = 1
        
        bumenBtn.layer.borderColor = UIColor.lightGray.cgColor
        bumenBtn.layer.borderWidth = 1
        
        oldNewBtn.layer.borderColor = UIColor.lightGray.cgColor
        oldNewBtn.layer.borderWidth = 1
        
        
        
    }
    
    //获取使用人、使用本部门、新旧程度的数据
    private func getChooseData(){
        
    
        userData = [["item":"占益益民占益民","id":"1"],["item":"曾诚","id":"1"],["item":"陈莹","id":"1"],["item":"张威","id":"1"],["item":"伏丹","id":"1"],["item":"张云霄","id":"1"],["item":"张赛","id":"1"],["item":"孙萌","id":"1"],["item":"李倩倩","id":"1"],["item":"任金玲","id":"1"],["item":"曾诚","id":"1"],["item":"陈莹","id":"1"],["item":"张威","id":"1"],["item":"伏丹","id":"1"],["item":"张云霄","id":"1"],["item":"张赛","id":"1"],["item":"孙萌","id":"1"],["item":"李倩倩","id":"1"],["item":"任金玲","id":"1"]]
        
       bumenData = [["item":"信息中心","id":"1"],["item":"商学院haha ","id":"1"],["item":"采购部","id":"1"],["item":"财务部","id":"1"],["item":"行政部","id":"1"]]
        
        
       oldNewData = [["item":"九成新","id":"1"],["item":"八成新","id":"1"],["item":"七成新","id":"1"],["item":"六成新","id":"1"],["item":"五成新","id":"1"]]
        
        
    }
    
    
    
    ///取消按钮点击
    @IBAction func cancelClick(_ sender: Any) {
        
        self.dismiss(animated: true) { 
            
        }
    }
    
    ///确定按钮点击
    @IBAction func sureBtnClick(_ sender: Any) {
        
        
    }
    
    //使用人点击
    @IBAction func userBtnclick(_ sender: UIButton) {

        let popmenu = YMPopMenu(frame: self.view.bounds, dataSource:userData!)

        view.addSubview(popmenu)
        weak var weakSelf = self
        popmenu.callBack = {(id :String , title : String) in
            weakSelf?.userBtn.setTitle(title, for: .normal)
            YMLog.log(item: "\(title) ==== \(id)")
        }
      
    }
    
  
    
    //部门点击
    @IBAction func bumenBtnClick(_ sender: UIButton) {

        let popmenu = YMPopMenu(frame: self.view.bounds, dataSource:bumenData!)
        
        
        view.addSubview(popmenu)
        weak var weakSelf = self
        popmenu.callBack = {(id :String , title : String) in
            weakSelf?.bumenBtn.setTitle(title, for: .normal)
            YMLog.log(item: "\(title) ==== \(id)")
        }
    }
    
    //新旧程度点击
    @IBAction func oldNewBtnClick(_ sender: UIButton) {

        let popmenu = YMPopMenu(frame: self.view.bounds, dataSource:oldNewData!)
        
        
        view.addSubview(popmenu)
        weak var weakSelf = self
        popmenu.callBack = {(id :String , title : String) in
            weakSelf?.oldNewBtn.setTitle(title, for: .normal)
            YMLog.log(item: "\(title) ==== \(id)")
        }
    }
    
    
    deinit {
        
        //析构时 ，解除强引用，避免不能释放
        CommonMenuView.clearMenu()
    }
  
    
    
    
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    

}
